<extend name="Public:mainbase" />
<block name="content">
<script language="javascript" src="__PUBLIC__/js/member.js?{:time()}"></script>  
<!--  内容列表   -->
<form name="form2" method="post">
<table width="98%" class="table table-bordered  table-hover table-condensed "  align="center">
<tr bgcolor="#E7E7E7" >
	<td height="28" colspan="11" background="__PUBLIC__/images/tbg.gif" style="padding-left:10px;">
	◆ 公告列表 &nbsp;&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-xs btn-warning" data-toggle="modal" data-target=".newjobbox">添加公告</button>
	</td>
</tr>
<tr align="center" bgcolor="#FBFCE2" height="25">
	<td width="6%">ID</td>
	<td width="4%">选择</td>
	<td width="28%">标题</td>
	<td width="28%">内容</td>
	<td width="10%">发表时间</td>
	<td width="10%">操作</td>
</tr>
<foreach name="noticeList" item="val">
<tr align='center' bgcolor="#FFFFFF" height="26">
	<td nowrap>{$val.nid}</td>
	<td>
		<input name="nid" type="checkbox" value="{$val.nid}" class="np" />
	</td>
	<td>{$val.title}</td>
	<td>{$val.content|mb_substr=0,30,'utf-8'}</td>
	<td>{$val.createtime|date="y-m-d H:i",###}</td>
	<td>
		<a href="javascript:;" data-nid='{$val.nid}' class='editjob'>修改</a>
		|
		<a href="javascript:;" data-nid='{$val.nid}' class='deljob'>删除</a>
		|
		<a href="javascript:;" data-nid='{$val.nid}' class='push'>推送</a>
	</td>
</tr>
</foreach>
<tr bgcolor="#ffffff">
<td height="36" colspan="11">
	&nbsp;
	<a href="javascript:selAll()" class="btn btn-xs btn-info"><i class='glyphicon glyphicon-ok'></i> 全选</a>
	<a href="javascript:noSelAll()" class="btn btn-xs btn-info"><i class='glyphicon glyphicon-remove'></i> 取消</a>
	<!-- <a href="javascript:checkArc(0)" class="btn btn-xs btn-info">&nbsp;审核&nbsp;</a> -->
	<a href="javascript:;" id="deljoball" class="btn btn-xs btn-info"><i class="glyphicon glyphicon-trash"></i> 删除</a>
</td>
</tr>
</form>
<tr align="right" bgcolor="#F9FCEF">
	<td height="36" colspan="11" align="center">
		<div class='page'>{$showpage}</div>
	</td>
</tr>
</table>

<!--  搜索表单  -->
<form name='form3' action='{:U('Admin/System/job')}' method='get'>
<input type='hidden' name='dopost' value='listArchives' />
<table width='98%'  class='table' align="center" style="margin-top:8px">
  <tr bgcolor='#EEF4EA'>
    <td background='__PUBLIC__/images/wbg.gif' align='center'>
      <table border='0' cellpadding='0' cellspacing='0' height="32">
        <td nowrap>职位名称：</td>
        <td width='130'>
          	<input type='text' name='name' value='' style='width:120px' />
        </td>
       <td>
          <input name="imageField" type="image" src="__PUBLIC__/images/button_search.gif" width="60" height="22" border="0" class="np" />
       </td>
      </tr>
     </table>
   </td>
  </tr>
</table>
</form>


<!-- 添加职位弹窗 -->
<div class="modal fade newjobbox" tabindex="-1" role="dialog" aria-labelledby="add_user_jump" id='newjobbox'>
  <div class="modal-dialog modal-sm" style="width:40%">
  		
    <div class="modal-content">
		<div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="myModalLabel">添加公告信息</h4>
	    </div>
		<form action="" method="POST" class="form-horizontal" style="padding:15px 0">
		<div class="form-group">
			<label for="username" class="col-sm-2 control-label">公告标题</label>
			<div class="col-sm-5">
				<input name="title" type="text" placeholder="公告标题" value="" class="form-control" value="">
			</div>
		</div>

		<div class="form-group">
			<label for="username" class="col-sm-2 control-label">公告内容</label>
			<div class="col-sm-5">
				<textarea name="content" class="form-control" rows="3" cols="10"></textarea>
			</div>
		</div>

		<div class="form-group">
			<label for="realname" class="col-sm-2 control-label">范围</label>
			<div class="col-sm-5">
				<input type="checkbox" class="channels_selected_all" name="" value="" /><a href="javascript:;">全选</a>
 				<ul class="menu">
					<foreach name="channels" item="channel">
						<li>
				            <input type="checkbox" name="channels[]" value="{$channel.chid}" data-id="0" /><a href="javascript:;">{$channel.name}</a>
				            <ul>
				            	<foreach name="jobs" item="job">
				                <li>&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="jobs_{$channel.chid}[]" data-id="{$channel.chid}" value="{$job.jid}" /><a href="javascript:;">{$job.name}</a></li>
				                </foreach> 
				            </ul>
				        </li>	
				    </foreach> 
			    </ul>
			</div>
		</div>

		<div class="add-error-message error item"></div>

		<div class="form-group">
		    <div class="col-sm-offset-2 col-sm-10">
		      <button type="button" class="btn btn-success" id="newjobBtn">确定添加</button>
		      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		      <button type="button" class="btn btn-danger"  data-dismiss="modal">取消</button>
		    </div>
		  </div>
		</form>
    </div>
  </div>
</div>


<!-- 添加用户弹窗 -->
<div class="modal fade editjobbox" tabindex="-1" role="dialog" aria-labelledby="edit_user_jump" id='editjobbox'>
  <div class="modal-dialog modal-sm" style="width:40%">
  		
    <div class="modal-content">
		<div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="myModalLabel">修改该职位信息</h4>
	    </div>
		<form action="" method="POST" class="form-horizontal" style="padding:15px 0">
		<div class="form-group">
			<label for="username" class="col-sm-2 control-label">公告标题</label>
			<div class="col-sm-5">
				<input name="title" type="text" placeholder="公告标题" value="" class="form-control" value="">
			</div>
		</div>

		<div class="form-group">
			<label for="username" class="col-sm-2 control-label">公告内容</label>
			<div class="col-sm-5">
				<textarea name="content" class="form-control" rows="3" cols="10"></textarea>
			</div>
		</div>

		<div class="form-group">
			<label for="realname" class="col-sm-2 control-label">范围</label>
			<div class="col-sm-5"> 
		        <input type="checkbox" class="channels_selected_all" name="" value="" /><a href="javascript:;">全选</a>
 				<ul class="menu">				
					<foreach name="channels" item="channel">
						<li>
				            <input type="checkbox" name="channels[]" value="{$channel.chid}" data-id="0" data-chid="{$channel.chid}" /><a href="javascript:;">{$channel.name}</a>
				            <ul>
				            	<foreach name="jobs" item="job">
				                <li>&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="jobs_{$channel.chid}[]" data-id="{$channel.chid}" data-jid="{$channel.chid}_{$job.jid}" value="{$job.jid}" /><a href="javascript:;">{$job.name}</a></li>
				                </foreach> 
				            </ul>
				        </li>	
				    </foreach> 
			    </ul>
			</div>
		</div>

		<div class="add-error-message error item"></div>

		<div class="form-group">
		    <div class="col-sm-offset-2 col-sm-10">
		      <input type="hidden" name="nid" value="0" />
		      <button type="submit" class="btn btn-success" id="editjobBtn">确定修改</button>
		      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		      <button type="button" class="btn btn-danger"  data-dismiss="modal">取消</button>
		    </div>
		  </div>
		</form>
    </div>
  </div>
</div>

<!-- <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/SimpleTree.css"/>
<script type="text/javascript" src="__PUBLIC__/js/SimpleTree.js"></script> -->
<link rel="stylesheet" href="__PUBLIC__/css/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="__PUBLIC__/js/jquery.ztree.core.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery.ztree.excheck.min.js"></script>

<script type="text/javascript">
	$('.deljob').click(function(){
		if(confirm('是否确定删除此职位？')){
			var obj=this;
			$.get('{:U("ajaxDelNotice")}?nid='+$(obj).data('nid'),function(data){
				if(data.status == 1){
					$(obj).parents('tr').remove();
				}
			})
		}
	})

	$('#deljoball').click(function(){
		if(confirm('是否确定删除？')){
			var id = $('[name=nid]:checked').map(function(){
				return $(this).val();
			}).get().join();

			$.post('{:U("ajaxDelNotice")}', {'jid': id},function(data){
				if(data.status == 1){
					$('[name=jid]:checked').parents('tr').remove();
				}
			})
		}
	})

	$('#newjobbox').on('show.bs.modal', function (e) {
  		$('#newjobbox form').get(0).reset();
	})

	$('#newjobBtn').on('click', function () {
  		$.post("{:U('Admin/System/ajaxNoticeAdd')}", $('.newjobbox form').serialize(), function (data) {
  			if(data.status == 1) {
  				location.reload();
  			} else {
  				alert(data.msg);
  			}
  		});
	});

	$('.editjob').click(function(){
		$('#editjobbox form').get(0).reset();
		$.get("{:U('Admin/System/ajaxNoticeData')}?nid=" + $(this).data('nid'), function(data){
  			if(data.status == 1){
  				$("#editjobbox input[name='title']").val(data.info['title']);
  				$("#editjobbox textarea[name='content']").val(data.info['content']);
  				$("#editjobbox input[name='nid']").val(data.info['nid']);

  				for(var i in data.info['relation']) {
  					$('input[data-chid="' + i + '"]').prop('checked', true);
  					for(var n in data.info['relation'][i]) {
  						$('input[data-jid="' + i + '_' + data.info['relation'][i][n] + '"]').prop('checked', true);
  					}
  				}
  			}
  		}, 'json')
		$('#editjobbox').modal('show');
	});


	$('#editjobBtn').on('click', function () {
		var data = 
  		$.post("{:U('Admin/System/ajaxNoticeEdit')}", $('.editjobbox form').serialize(), function (data) {
  			if(data.status == 1) {
  				$('#editjobbox').modal('hide');
  			} else {
  				alert(data.msg);
  			}
  		});
	});

	$('.menu ul').hide();
	$('.menu a').on('click', function () {
		$(this).next().toggle();
	});

	$('.menu input').on('click', function () {
		$(this).siblings('ul').find('input').prop('checked', $(this).prop('checked'));

		if($(this).closest('ul').find('input:checked').prop('checked') == undefined) {

			$(this).parents('ul').siblings('input').prop('checked', false);
		} else {
			$(this).parents('ul').siblings('input').prop('checked', true);
			$(this).parents('ul').siblings('input').css('background', '#666');
		}
		
	});
	
	$('.push').on('click', function () {
		var nid = $(this).data('nid');
		$.get("{:U('Mapi/Notice/pushNotice')}?nid=" + nid, function(data) {
			if(data.result == 'ok') {
				alert('推送成功');
			} else {
				alert(data.result);
			}
		});
	});

	$('.channels_selected_all').on('click', function () {
		$(this).nextAll().find('input').prop('checked', $(this).prop('checked'));
	});

</script>
</block>